from fastapi import status
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from typing import Union, Optional, Any, Dict
from starlette.exceptions import HTTPException
import http
import typing

class respJsonBase(BaseModel):
    code: int
    msg: str
    data: Union[dict, list]


def returnJson(code: int = 200, msg: str = "Success", data: Union[list, dict, str] = None):
    """ 接口成功返回 """
    return JSONResponse(
        status_code=status.HTTP_200_OK,
        content={
            'code': code,
            'msg': msg,
            'data': data or {}
        }
    )
